using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Comteck.Dto.Sys;
using Comteck.Entities.Sys;
using Comteck.Ktt.Services.Infrastructure;
using ExpressMapper.Extensions;

namespace Comteck.Ktt.Services.Sys {
  /// <summary>
  /// 
  /// </summary>
  public class MenuAuthService  : BaseKttService, IMenuAuthService {
    private readonly IKttRepository<MenuAuth, string> _menuAuthRepository;

    public MenuAuthService(IKttUnitOfWork unitOfWork) : base(unitOfWork) {
      _menuAuthRepository = _unitOfWork.GetRepository<MenuAuth, string>();
    }

    /// <summary>
    /// 查询全部列表
    /// </summary>
    /// <returns></returns>
    public async Task<IEnumerable<MenuAuthDto>> GetLastMenuListAsync() {
      var list = await _menuAuthRepository.GetAllAsync();
      return list.Where(x => x.Form_Path.IsNotNullOrEmpty()).MapTo<IEnumerable<MenuAuthDto>>();
    }

    /// <summary>
    /// 查询全部列表
    /// </summary>
    /// <returns></returns>
    public async Task<IEnumerable<MenuAuthDto>> GetActiveDtosAsync() {
      var list = await _menuAuthRepository.FindAsync(x => x.Status == 1);
      return list.MapTo<IEnumerable<MenuAuthDto>>();
    }

  }
}
